﻿/***********************************************************************************************
 * 
 * ProjectName: WMSSoft.Lib.Interfaces
 * 
 * Description: Provide the Interface to describe a DataSource used on WinKStart
 * 
 * Created:     21.07.2014
 * 
 * Author:      matthias wagler - matthias@WMSSoft.de
 * 
 * Copyright:   Copyright 2014 by WMSSoft.de
 * 
 * License:     GPLv3
 * 
 * History:     21.07.2014 - matthias wagler matthias@WMSSoft.de   -   Created
 * 
 **********************************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WMSSoft.Lib.Basic;

namespace WMSSoft.Lib.Interfaces
{

    /// <summary>
    /// Interface used to Create a DataSource - Assembly
    /// </summary>
    public interface iWinKStartDataSource
    {
        /// <summary>
        /// Contains the data source unique name
        /// </summary>
        string Name { get; set; }

        /// <summary>
        /// Contains the assembly file name to load data source from
        /// </summary>
        string AssemblyName { get; set; }

        /// <summary>
        /// Contains the Name of the class that provide the data
        /// </summary>
        string ClassName { get; set; }

        /// <summary>
        /// Contains the Name to view in settings page if the datasource
        /// is searchable
        /// </summary>
        string ShortName { get; set; }

        /// <summary>
        /// If true the DataSource is viewed in settingspage to select for searching
        /// </summary>
        bool Searchable { get; set; }

        /// <summary>
        /// Get the Date who last updated
        /// </summary>
        long LastUpdated { get; }

        /// <summary>
        /// Contains the data providing from class
        /// </summary>
        iWinKStartItem Data { get; set; }

        /// <summary>
        /// Contains a List with all user defined DataItems
        /// </summary>
        List<iWinKStartItem> Items { get; set; }

        /// <summary>
        /// Contains all File Extension to Filter links
        /// </summary>
        Dictionary<string, KeyValueAssignment> Assignments { get; set; }

        /// <summary>
        /// Contains all File Extension to Filter links
        /// </summary>
        Dictionary<string, KeyValueAssignment> Options { get; set; }
        
        /// <summary>
        /// Initialise the Class and start Data loading
        /// </summary>
        /// <returns></returns>
        bool Init();

        /// <summary>
        /// Stop all running threads
        /// </summary>
        /// <returns></returns>
        bool UnloadDataSource();

        /// <summary>
        /// add item to data source
        /// </summary>
        /// <param name="Item"></param>
        /// <param name="ParentKey"></param>
        /// <returns></returns>
        bool AddItem(iWinKStartItem Item, string ParentKey);

        /// <summary>
        /// add a dictionary of items to data source
        /// </summary>
        /// <param name="Childs">Dictionary with Child Items to add</param>
        /// <param name="ParentKey">Key for the Parent Data Item </param>
        /// <returns></returns>
        bool AddChilds(Dictionary<string, object> Childs, string ParentKey);

        /// <summary>
        /// Remove given Item from data source
        /// </summary>
        /// <param name="ItemKey">Key from Item to remove</param>
        /// <param name="ParentKey">Path to the Parent</param>
        /// <returns></returns>
        bool DeleteItem(string ItemKey, string ParentKey);

        /// <summary>
        /// Delete all Childs in the given Parent
        /// </summary>
        /// <param name="ParentKey">Key of the Parent Element</param>
        void ClearItems(string ParentKey);

        /// <summary>
        /// Event to notify that data was successful loaded/update
        /// </summary>
        event EventHandler LoadCompleted;
    }
}
